package com.dubito.palette

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.Fragment

/**
 * @author by liliang on 2020/6/14 4:01 PM
 */
class TabFragment : Fragment() {

    private lateinit var bitmap: Bitmap
    private lateinit var tvBg: TextView
    private lateinit var tvDescription: TextView


    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment, container, false)
        val tab = arguments!!.getInt("TAB")
        tvBg = view.findViewById(R.id.tvBg)
        tvDescription = view.findViewById(R.id.tvDescription)
        val imageView = view.findViewById<ImageView>(R.id.ivImg)
        when (tab) {
            1 -> {
                bitmap = BitmapFactory.decodeResource(resources, R.drawable.jt)
                tvDescription.text = "+王大锤"
            }
            2 -> {
                bitmap = BitmapFactory.decodeResource(resources, R.drawable.fx)
                tvDescription.text = "王大锤"
            }
            3 -> {
                bitmap = BitmapFactory.decodeResource(resources, R.drawable.xsea)
                tvDescription.text = "王大锤"
            }
            4 -> {
                bitmap = BitmapFactory.decodeResource(resources, R.drawable.pg)
                tvDescription.text = "王大锤"
            }
        }
        imageView.setImageBitmap(bitmap)
        return view
    }

    fun setContent(rgb: Int) {
        tvBg.setBackgroundColor(rgb)
        tvBg.alpha = 0.5f
    }

    fun getBitmap(): Bitmap? {
        return bitmap
    }
}